home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume10 / parseargs.p2 < prev    next >
Encoding:
Text File  |  1990-02-26  |  4.0 KB  |  156 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Xenix Support, FICC
  3. subject: v10i083: Parse ARGH: missing file from parseargs patches
  4. from: peter@ficc.uu.net (Peter da Silva)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 10, Issue 83
  8. Submitted-by: peter@ficc.uu.net (Peter da Silva)
  9. Archive-name: parseargs.p2
  10.  
  11. This isn't strictly speaking a patch... it's an extra file required by the
  12. first set of patches. I should just have posted the whole thing again...
  13.  
  14. :
  15. #! /bin/sh
  16. # This is a shell archive, created at Ferranti International Controls Corp.
  17. # by peter (Peter da Silva +1 713 274 5180) on Fri Feb 23 05:45:53 1990
  18. # Remove anything before the "#! /bin/sh" line, then unpack it by saving
  19. # it into a file and typing "sh file".  If you do not have sh, you need 
  20. # unshar, a dearchiving program which is widely available.  In the absolute
  21. # wost case, you can crack the files out by hand.
  22. # If the archive is complete, you will see the message "End of archive."
  23. # at the end.
  24. # This archive contains the following files...
  25. # 'arglist.c'
  26. # To extract them, run the following through /bin/sh
  27. echo x - arglist.c
  28. sed 's/^X//' > arglist.c << '//END_OF_FILE'
  29. X#include <parseargs.h>
  30. X#include <ctype.h>
  31. X
  32. X#ifdef __STDC__
  33. Xtypedef void *pointer;
  34. X#else
  35. Xtypedef char *pointer;
  36. X#endif
  37. X
  38. Xextern pointer malloc();
  39. X
  40. X#define ALL_AD        ad = argd; ad->ad_name != '\0'; ad++
  41. X#define ALL_DEFS    ad = _DefaultArgs; ad->ad_name != '\0'; ad++
  42. X
  43. Xextern char    *ProgName;
  44. X
  45. X/* Argument list utility routines. After processing, parseargs calls
  46. X * cleanup_lists to reverse all argument lists so they stay in order.
  47. X */
  48. X
  49. X/* Reverse a list */
  50. Xstruct arglist *reverselist(from)
  51. Xstruct arglist *from;
  52. X{
  53. X    struct arglist *to, *tmp;
  54. X
  55. X    to = NULL;
  56. X    while(from) {
  57. X        tmp = from; /* remove top from old list */
  58. X        from = from->nl_next;
  59. X        tmp->nl_next = to; /* insert top in new list */
  60. X        to = tmp;
  61. X    }
  62. X    return to;
  63. X}
  64. X
  65. X/* Reverse all arglists in argd */
  66. Xcleanup_lists(argd)
  67. XARGDESC *argd;
  68. X{
  69. X    ARGDESC *ad;
  70. X
  71. X    for(ALL_AD) {
  72. X        if( (ad->ad_flags & ARGLIST) &&
  73. X            *(struct arglist **)ad->ad_valp) {
  74. X            *(struct arglist **)ad->ad_valp =
  75. X                reverselist( *(struct arglist **)ad->ad_valp );
  76. X        }
  77. X    }
  78. X}
  79. X
  80. X/*
  81. X**  ARGlist -- list argument translation routines.
  82. X**
  83. X**    Each of these converts a parameter value to the internal form,
  84. X**    including validity checking.  Their parameters and return values
  85. X**    all behave identically. These are the routines for dealing with
  86. X**    lists...
  87. X**
  88. X**    Parameters:
  89. X**        ad -- the argument descriptor for this parameter.
  90. X**        vp -- a pointer to the string input value.
  91. X**        copyf -- if TRUE, the value will be destroyed later,
  92. X**            and so should be copied if it will be retained
  93. X**            (as for a string).
  94. X**
  95. X**    Returns:
  96. X**        TRUE -- if the conversion was successful.  The actual
  97. X**            value should be added to the list stored in the
  98. X**            location indicated by ad->ad_valp.
  99. X**        FALSE -- if the conversion failed.  The reason for failure
  100. X**            should be diagnosed using usrerr().
  101. X**
  102. X**    Side Effects:
  103. X**        The value should be stored through ad->ad_valp.
  104. X*/
  105. X
  106. XBOOL
  107. XlistStr(ad, vp, copyf)
  108. X    register ARGDESC *ad;
  109. X    register char *vp;
  110. X    BOOL copyf;
  111. X{
  112. X    char *cp;
  113. X    struct arglist *nl;
  114. X
  115. X    if (copyf)
  116. X    {
  117. X        register int i;
  118. X
  119. X        i = strlen(vp) + 1;
  120. X        cp = (char *) malloc(i);
  121. X        if(!cp) {
  122. X            usrerr("out of memory saving string %s", ad->ad_prompt);
  123. X            return FALSE;
  124. X        }
  125. X        bcopy(vp, cp, i);
  126. X    }
  127. X    else
  128. X    {
  129. X        cp = vp;
  130. X    }
  131. X
  132. X    nl = (struct arglist *) malloc(sizeof *nl);
  133. X    if(!nl) {
  134. X        usrerr("out of memory saving arg %s", ad->ad_prompt);
  135. X        if(copyf) free(cp);
  136. X        return FALSE;
  137. X    }
  138. X
  139. X    nl->nl_next = *(struct arglist **) ad->ad_valp;
  140. X    nl->nl_val = (ARBPTR)cp;
  141. X    *(struct arglist **) ad->ad_valp = nl;
  142. X    return (TRUE);
  143. X}
  144. X
  145. //END_OF_FILE
  146. echo "End of archive."
  147. # end of archive.
  148. exit 0
  149. -- 
  150.  _--_|\  Peter da Silva. +1 713 274 5180. <peter@ficc.uu.net>.
  151. /      \
  152. \_.--._/ Xenix Support -- it's not just a job, it's an adventure!
  153.       v  "Have you hugged your wolf today?" `-_-'
  154.  
  155.  
  156.